USE [Forums]
GO

/****** Object:  StoredProcedure [dbo].[SPAnswerStatusUpdate]    Script Date: 08/10/2012 11:03:00 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[SPAnswerStatusUpdate]
	@voted int 
	,@isBest bit
	,@answerID int
AS
BEGIN TRY
	BEGIN TRANSACTION
	
	Declare @votedCurrent int;
	Declare @isBestCurrent bit;
	
	select @votedCurrent = voted from ASK_Answers where answerID = @answerID
	select @votedCurrent =isNULL(@voted + @votedCurrent,0);
	
	update ASK_Answers 
	set
	voted = @votedCurrent,
	isBest = @isBest
	where
	answerID = @answerID
	
	COMMIT

END TRY
BEGIN CATCH
	IF @@TRANCOUNT > 0
		ROLLBACK

  -- Raise an error with the details of the exception
	DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
	SELECT @ErrMsg = ERROR_MESSAGE(),
		 @ErrSeverity = ERROR_SEVERITY()

	RAISERROR(@ErrMsg, @ErrSeverity, 1)

END CATCH


GO


